package com.zhz.mall.portal.controller;

import com.zhz.mall.common.api.CommonResult;
import com.zhz.mall.portal.dto.HomeGoodsSaleDTO;
import com.zhz.mall.portal.dto.HomeMenusBannerDTO;
import com.zhz.mall.portal.dto.HomeMenusDTO;
import com.zhz.mall.portal.modules.pms.service.PmsProductCategoryService;
import com.zhz.mall.portal.modules.sms.model.SmsHomeAdvertise;
import com.zhz.mall.portal.modules.sms.service.SmsHomeAdvertiseService;
import com.zhz.mall.portal.modules.sms.service.SmsHomeCategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhouhengzhe
 * @date 2023/2/4
 */
@RestController
@RequestMapping("/home")
@Api("首页内容管理")
public class HomeController {

    @Autowired
    private PmsProductCategoryService productCategoryService;

    @Autowired
    private SmsHomeAdvertiseService SmsHomeAdvertiseService;

    @Autowired
    private SmsHomeCategoryService smsHomeCategoryService;

    /**
     * 获取首页类型导航栏和数据
     * get("/home/menus")
     */
    @GetMapping("/menus_banner")
    public CommonResult<HomeMenusBannerDTO> getMenus() {
        //分类导航
        List<HomeMenusDTO> homeMenusDtoList = productCategoryService.getMenus();
        //banner
        List<SmsHomeAdvertise> smsHomeAdvertiseList = SmsHomeAdvertiseService.getHomeBanners();
        return CommonResult.success(
                HomeMenusBannerDTO
                        .builder()
                        .homeMenusList(homeMenusDtoList)
                        .homeAdvertisesList(smsHomeAdvertiseList)
                        .build()
        );
    }

    @GetMapping("/goods_sale")
    public CommonResult<List<HomeGoodsSaleDTO>> getGoodsSale() {
        return CommonResult.success(smsHomeCategoryService.getGoodsSale());
    }

}
